package com.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@FeignClient(value = "sayHelloServiceProvider",fallback=FeignClientHystrixToolFallback.class)
interface FeignClientHystrixTool
{
	@RequestMapping(method = RequestMethod.GET, value = "/hello/{name}")
	String sayHelloInClient(@RequestParam("name") String name);
}

@Component
class FeignClientHystrixToolFallback implements FeignClientHystrixTool{

	public String sayHelloInClient(String name) {		
		return "In Fallback Function.";
	}
	
}
 
@RestController
public class ControllerForFeignHystrix {
		
	@Autowired
	private FeignClientHystrixTool tool;
	
	@RequestMapping(value = "/callHelloAsHystrix/{username}", method = RequestMethod.GET)
	public String callHelloAsHystrix(@PathVariable("username") String username) {
		return tool.sayHelloInClient(username);
	}
	
	
	
	
}
